import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 消除点击重复路由报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    component: () => import('../views/login/index.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/index.vue')
  },
  // 首页
  {
    path: '/home',
    name:'home',
    meta: {
      depth: 0
    },
    component: () => import('../views/home/index.vue')
  },
  // 个人中心
  {
    path: '/my',
    name:'my',
    component: () => import('@/views/my/index.vue')
  },
  {
    path: '/userInfos',
    name:'userInfos',
    component: () => import('@/views/my/components/UserInfos.vue')
  },
  {
    path: '/about',
    name:'about',
    component: () => import('@/views/my/components/AboutView.vue')
  },
  {
    path: '/changePwd',
    name:'changePwd',
    component: () => import('@/views/my/components/ChangePwd.vue')
  },
  {
    path: '/userInfos',
    name:'userInfos',
    component: () => import('@/views/my/components/UserInfos.vue')
  },
  {
    path: '/demo',
    name:'demo',
    component: () => import('@/views/demo/index.vue')
  }
  
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to, from, next) => {
//   // 记录滚动条位置
//   if (from.meta.keepAlive) {
//     const $wrapper = document.querySelector('.app-wrapper'); // 列表的外层容器 注意找到滚动的盒子
//     const scrollTop = $wrapper ? $wrapper.scrollTop : 0;
//     from.meta.scrollTop = scrollTop;
//   }
//   next();
// });

export default router
